package com.etocrm.saas.lib.base.common.result.uam.util;

import com.etocrm.saas.lib.base.common.exception.RemoteBusinessException;
import com.etocrm.saas.lib.base.common.result.ResultCodeEnum;
import com.etocrm.saas.lib.base.common.result.uam.enums.ResponseEnum;
import com.etocrm.saas.lib.base.common.result.uam.vo.ResponseVO;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * UAM 通用结果集的 常用方法的封装
 * Created by Xs on 2022/11/24.
 */
@Slf4j
public class UAMResultUtil {

    /**
     * 判断远程方法业务是否成功, 失败则抛出异常.
     *
     * @param responseVO 返回的结果集对象
     */
    public static <T> void isSuccess(ResponseVO<T> responseVO) {
        Integer code = responseVO.getCode();
        if (!Objects.equals(code, ResponseEnum.SUCCESS.getCode())) {
            log.error(ResultCodeEnum.FEIGN_BUSINESS_WARN.getMessage() + "  返回业务code : {} , 返回异常描述 : {}", code, responseVO.getMessage());
            throw new RemoteBusinessException(ResultCodeEnum.FEIGN_BUSINESS_WARN);
        }
    }
}
